home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / ulog / Ulog_RecordLogin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-22  |  3.0 KB  |  106 lines

  1. /* 
  2.  * Ulog_RecordLogin.c --
  3.  *
  4.  *    Source code for the Ulog_RecordLogin procedure.
  5.  *
  6.  * Copyright 1988 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /sprite/src/lib/c/ulog/RCS/Ulog_RecordLogin.c,v 1.6 92/04/21 17:34:28 kupfer Exp $ SPRITE (Berkeley)";
  18. #endif not lint
  19.  
  20.  
  21. #include <ulog.h>
  22. #include "ulogInt.h"
  23.  
  24.  
  25. /*
  26.  *----------------------------------------------------------------------
  27.  *
  28.  * Ulog_RecordLogin --
  29.  *
  30.  *    Record information for a user in the database.
  31.  *
  32.  * Results:
  33.  *    -1 indicates an error, in which case errno indicates more details.
  34.  *    0 indicates success.
  35.  *
  36.  * Side effects:
  37.  *    The database file is updated.
  38.  *
  39.  *----------------------------------------------------------------------
  40.  */
  41.  
  42. int
  43. Ulog_RecordLogin(uid, location, portID)
  44.     int uid;        /* user identifier */
  45.     char *location;    /* string identifying user's location (host
  46.                or "terminal") */
  47.     int portID;        /* index into host's area in file*/
  48. {
  49.     struct timeval time;
  50.     int status;
  51.     char myHostName[ULOG_LOC_LENGTH];
  52.     char buffer[ULOG_RECORD_LENGTH];
  53.     Host_Entry *hostPtr;
  54.  
  55.  
  56.     if (portID >= ULOG_MAX_PORTS) {
  57.     syslog(LOG_WARNING,
  58.            "Unable to record login from %s for uid %d, port %d: maximum number of entries exceeded.",
  59.            location, uid, portID);
  60.     errno = EINVAL;
  61.     return(-1);
  62.     }
  63.     if (portID < 0) {
  64.     syslog(LOG_ERR, "Invalid port for recording login: %d\n", portID);
  65.     errno = EINVAL;
  66.     return(-1);
  67.     }
  68.     if (strlen(location) >= ULOG_LOC_LENGTH) {
  69.     syslog(LOG_ERR, "Ulog_RecordLogin: location name (%s) too large.",
  70.            location);
  71.     errno = EINVAL;
  72.     return(-1);
  73.     }
  74. #ifdef DEBUG
  75.     syslog(LOG_INFO, "Recording login for uid %d, port %d.", uid, portID);
  76. #endif 
  77.     status = gettimeofday(&time, (struct timezone *) NULL);
  78.     if (status == -1) {
  79.     return(status);
  80.     }
  81.     if (gethostname(myHostName, ULOG_LOC_LENGTH) < 0) {
  82.     syslog(LOG_ERR, "Ulog_RecordLogin: error in gethostname.\n");
  83.     return(-1);
  84.     }
  85.     hostPtr = Host_ByName(myHostName);
  86.     Host_End();
  87.     if (hostPtr == (Host_Entry *) NULL) {
  88.     syslog(LOG_ERR,
  89.            "Ulog_RecordLogin: error in Host_ByName for current host.\n");
  90.     return(-1);
  91.     }
  92.     bzero(buffer, ULOG_RECORD_LENGTH);
  93.     (void) sprintf(buffer, ULOG_FORMAT_STRING, uid, hostPtr->id, portID,
  94.              time.tv_sec, location);
  95.  
  96.     status = Db_WriteEntry(ULOG_FILE_NAME, buffer, 
  97.                hostPtr->id * ULOG_MAX_PORTS + portID,
  98.                ULOG_RECORD_LENGTH, DB_LOCK_BREAK);
  99.     if (status != 0) {
  100.     return(status);
  101.     }
  102.     status = Db_WriteEntry(LASTLOG_FILE_NAME, buffer, uid, ULOG_RECORD_LENGTH,
  103.                DB_LOCK_BREAK);
  104.     return(status);
  105. }
  106.